package com.gamota.mobi.model;

import android.app.Activity;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.gamota.mobi.R;
import com.gamota.mobi.adapter.AggregateListAdapter.RowType;
import com.gamota.mobi.adapter.Item;

public class SearchHeader implements Item {
	
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public void setListener(OnViewAllClickListener listener) {
		this.listener = listener;
	}

	public int getButtonColor() {
		return buttonColor;
	}

	public void setButtonColor(int buttonColor) {
		this.buttonColor = buttonColor;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getNumber() {
		return number;
	}

	public void setNumber(String number) {
		this.number = number;
	}

	private String name;
	private String number;
	private Typeface robotoItalic;
	private int buttonColor;
	private OnViewAllClickListener listener;
	private Activity context;
	private String type;
	
	public SearchHeader(Activity context){
		this.context = context;
		robotoItalic = Typeface.createFromAsset(context.getAssets(), context.getResources().getString(R.string.roboto_italic_condensed));
	}

	@Override
	public int getViewType() {
		// TODO Auto-generated method stub
		return RowType.HEADER_ITEM.ordinal();
	}

	@Override
	public View getView(LayoutInflater inflater, View convertView) {
		HeaderViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.search_header, null);
            holder = new HeaderViewHolder();
            holder.name = (TextView) convertView.findViewById(R.id.search_header_name);
            holder.number = (TextView) convertView.findViewById(R.id.btn_view_all);
            convertView.setTag(holder);
        } else {
            holder = (HeaderViewHolder) convertView.getTag();
        }
        holder.name.setText(name);
        holder.name.setTypeface(robotoItalic);
        holder.number.setBackgroundResource(buttonColor);
        holder.number.setText(String.format(context.getResources().getString(R.string.view_all_result), number));
        holder.number.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(listener != null){
					listener.onViewAllClick(type);
				}
			}
		});
        return convertView;
	}

	private class HeaderViewHolder {
		TextView name;
		TextView number;
	}
	
	public interface OnViewAllClickListener{
		public void onViewAllClick(String type);
	}
}
